import React, { useEffect } from 'react';
import { Button } from 'antd';
import { Link, useSelector, useDispatch } from 'umi';

export default () => {
  const dispatch = useDispatch()
  const { currentUser } = useSelector(({ global }) => global)
  useEffect(_ => {
    dispatch({ type: "global/fetchCurrent" })
  }, [])
  return (
    <div>
      {currentUser.Id ? <div>
        当前用户: {currentUser.Name}
        <Button onClick={_ => {
          dispatch({ type: "global/logout" })
        }}>退出登录</Button>
      </div> : <Button>
          <Link to="/login">login</Link>
        </Button>}
    </div>
  );
};
